<?php
namespace app\friend\controller;
use think\Controller;
use think\Session;
use think\Db;
use think\Request;

class Myfriend extends Controller
{
    public function index()
    {
        $id = Session::get('id');
        // var_dump($id);
        //当前用户信息
        $user = Db::table('user_info')->where('uid',$id)->find();
        // var_dump($user);

        //当前用户全部好友
        $friends = Db::table('friend')->alias('f')->join('user_info u','u.uid = f.fid')->where('f.uid',$id)->where('f.status',1)->select();
        
        // var_dump($friends);

        $this->assign('user',$user);
        $this->assign('friends',$friends);

        return $this->fetch('index/myfriend');
    }

    public function see()
    {
        $id = input('uid');
        // var_dump($id);
        $list1 = Db::table('user')->where('id',$id)->find();
            $list2 = Db::table('user_info')->where('uid',$id)->find();
            $this->assign('title','个人资料');
            $this->assign('list1',$list1);
            $this->assign('list2',$list2);
            $this->assign('id',$id);
            // var_dump($list1);
            // var_dump($list2);
            return $this->fetch('index/frienddata');
    }

    public function find()
    {
        $id = Session::get('id');
        // var_dump($id);
        //当前用户信息
        $user = Db::table('user_info')->where('uid',$id)->find();
        // var_dump($user);

        $name = Request::instance()->post('name');
        // var_dump($name);
        $friends = Db::table('user_info')->where('pname','like',"%$name%")->select();
        // var_dump($friends);
        $this->assign('user',$user);
        $this->assign('friends',$friends);

        return $this->fetch('index/myfriend');
    }
}
